package com.ruoyi.web.controller.part;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.system.domain.PartType;
import com.ruoyi.system.service.IPartTypeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PartLot;
import com.ruoyi.system.service.IPartLotService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 停车场信息Controller
 *
 * @author ruoyi
 * @date 2024-01-06
 */
@RestController
@RequestMapping("/part/lot")
public class PartLotController extends BaseController {
    @Autowired
    private IPartLotService partLotService;

    @Autowired
    private IPartTypeService partTypeService;

    /**
     * 查询停车场信息列表
     */
    @PreAuthorize("@ss.hasPermi('part:lot:list')")
    @GetMapping("/list")
    public TableDataInfo list(PartLot partLot) {
        startPage();
        List<PartLot> list = partLotService.selectPartLotList(partLot);
        return getDataTable(list);
    }

    /**
     * 导出停车场信息列表
     */
    @PreAuthorize("@ss.hasPermi('part:lot:export')")
    @Log(title = "停车场信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PartLot partLot) {
        List<PartLot> list = partLotService.selectPartLotList(partLot);
        ExcelUtil<PartLot> util = new ExcelUtil<PartLot>(PartLot.class);
        util.exportExcel(response, list, "停车场信息数据");
    }

    /**
     * 获取停车场信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('part:lot:query')")
    @GetMapping(value = "/{partLotId}")
    public AjaxResult getInfo(@PathVariable("partLotId") Long partLotId) {
        //return success(partLotService.selectPartLotByPartLotId(partLotId));
        PartLot partLot = partLotService.selectPartLotByPartLotId(partLotId);
        AjaxResult ajax = AjaxResult.success();
        ajax.put(AjaxResult.DATA_TAG, partLot);
        //  List<PartType> partTypes = partTypeService.selectPartTypeList(new PartType());
        //  ajax.put("partTypes", partTypes);
        return ajax;
    }

    /**
     * 新增停车场信息
     */
    @PreAuthorize("@ss.hasPermi('part:lot:add')")
    @Log(title = "停车场信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PartLot partLot) {
        partLot.setCreateBy(getUsername());
        return toAjax(partLotService.insertPartLot(partLot));
    }

    /**
     * 修改停车场信息
     */
    @PreAuthorize("@ss.hasPermi('part:lot:edit')")
    @Log(title = "停车场信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PartLot partLot) {
        return toAjax(partLotService.updatePartLot(partLot));
    }

    /**
     * 删除停车场信息
     */
    @PreAuthorize("@ss.hasPermi('part:lot:remove')")
    @Log(title = "停车场信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{partLotIds}")
    public AjaxResult remove(@PathVariable Long[] partLotIds) {
        return toAjax(partLotService.deletePartLotByPartLotIds(partLotIds));
    }
}
